<template>
  <view class="container">
    <u-tabs :current="current" :list="tabs" keyName="name" :scrollable="false" @change="handleTabChange"></u-tabs>
    <!-- 数据统计 -->
    <view v-if="current==1" class="content">
      <view class="section">
        <view class="title">统计数据</view>
        <up-row class="mt-[10rpx]" gutter="10">
          <up-col span="4">
            <view class="item mb-[20rpx]">
              <view class="item-title">营期人数</view>
              <view class="item-value" data-unit="人">{{ 0 }}</view>
            </view>
          </up-col>
          <up-col span="4">
            <view class="item mb-[20rpx]">
              <view class="item-title">观看人数</view>
              <view class="item-value" data-unit="人">{{ 0 }}</view>
            </view>
          </up-col>
          <up-col span="4">
            <view class="item mb-[20rpx]">
              <view class="item-title">上线率</view>
              <view class="item-value" data-unit="%">{{ 0 }}</view>
            </view>
          </up-col>
          <up-col span="4">
            <view class="item">
              <view class="item-title">完播人数</view>
              <view class="item-value" data-unit="人">{{ 0 }}</view>
            </view>
          </up-col>
          <up-col span="4">
            <view class="item">
              <view class="item-title">完播率</view>
              <view class="item-value" data-unit="%">{{ 0 }}</view>
            </view>
          </up-col>
          <up-col span="4">
            <view class="item">
              <view class="item-title">团队人数</view>
              <view class="item-value" data-unit="人">{{ 0 }}</view>
            </view>
          </up-col>
        </up-row>
      </view>
      <view class="section">
        <view class="title">转化漏斗图</view>
        <view class="funnel">
          <view class="funnel-item" :style="{
            '--width': 600 - index*100 + 'rpx',
            '--height': 120 - index*15 + 'rpx',
            '--color': `rgb(0, ${122 + index*30}, 255)`
          }" v-for="(item, index) in 4" :key="index">
            <view class="funnel-item-label">客户</view>
            <view class="funnel-item-total">{{ 0 }}</view>
            <view class="funnel-item-rate">{{ 0 }}%</view>
          </view>
        </view>
      </view>
    </view>
    <!-- 数据明细 -->
    <answer v-if="current==0"></answer>
  </view>
</template>

<script lang="ts" setup>
import { computed, ref } from 'vue';
import Answer from './answer.vue';


const tabs = ref([
  { name: '参与记录' },
  { name: '数据概况' },
]); 

const current = ref(0)

function handleTabChange(e:any) {
  console.log(e);
  
  current.value = e.index
}
</script>

<style lang="scss" scoped>
.u-tabs {
  box-shadow: 0 0 10rpx rgba(0, 0, 0, 0.05);
  background-color: #fff;
  border-bottom: 1px solid #f5f5f5;
}
.u-row {
  flex-wrap: wrap;
}
.container {
  min-height: 100vh;
  background-color: #f7f7f7;

  .content {
    padding: 20rpx 30rpx;

    .section {
      padding: 30rpx;
      background-color: #fff;
      border-radius: 24rpx;
      margin-bottom: 30rpx;
    }
    .title {
      font-weight: bold;
    }

    .item {
      background-color: #f7f7f7;
      border-radius: 12rpx;
      padding: 12rpx 20rpx;

      .item-title {
        font-size: 24rpx;
        font-weight: bold;
        line-height: 40rpx;
      }

      .item-value {
        line-height: normal;
        font-size: 40rpx;
        font-weight: bold;
        color: var(--primary-color);

        &::after {
          content: attr(data-unit);
          font-size: 20rpx;
          font-weight: normal;
        }
      }
    }

    .funnel {
      margin-top: 30rpx;
    }

    .funnel-item {
      height: var(--height);
      width: var(--width);
      margin: auto;
      margin-bottom: 40rpx;
      position: relative;
      display: flex;
      flex-direction: column;
      
      .funnel-item-label {
        position: absolute;
        top: 0;
        right: 0;
        transform: translateX(50%);
        font-size: 24rpx;
      }     
      .funnel-item-total {
        flex: 1;
        position: relative;
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 1;
        color: #fff;
        overflow: hidden;

        &::after {
          content: '';
          z-index: -1;
          position: absolute;
          left: 50%;
          bottom: 0;
          transform: translate(-50%, 0);
          height: 0;
          width: 0;
          border-width: calc(var(--height)/2) calc(var(--width)/2) calc(var(--height)/2) calc(var(--width)/2);
          border-style: solid;
          border-color: transparent transparent var(--color) transparent;
        }
      }
      .funnel-item-rate {
        flex: 1;
        position: relative;
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 1;
        overflow: hidden;

        &::after {
          content: '';
          z-index: -1;
          position: absolute;
          left: 50%;
          top: 0;
          transform: translate(-50%, 0);
          height: 0;
          width: 0;
          border-width: calc(var(--height)/2) calc(var(--width)/2) calc(var(--height)/2) calc(var(--width)/2);
          border-style: solid;
          border-color: #f5f5f5 transparent transparent  transparent;
        }
      }

      &:first-child {
        height: calc(var(--height) /2);
        .funnel-item-total {
          display: none;
        }
      }
      &:last-child {
        height: calc(var(--height) /2);
        .funnel-item-rate {
          display: none;
        }
      }
    }
  }
}
</style>